package services.AC01;

import java.util.*;

import com.*;
import com.util.Util;
import vo.system.AC01;
import webservice.ServicePeople;
/**
 * PersonMgrFacade:个人基础信息管理services
 * @author fcl
 * @version Wed Dec 23 16:16:39 CST 2015 bjh
 * @since 1.0
 */
public class AC01Services {
	PublicSystem sys=PublicSystem.getInstance();
	
	ServicePeople service = new ServicePeople();

	/**
	 * 查询个人基础信息
	 * @author bjh
	 * @param obj
	 * @param parms
	 * @throws Exception
	 */
    public HashMap getAc01(Object[] obj,HashMap parms) throws Exception {
    	String sql="select * from v_ac01 where ('"+obj[0]+"' is null or aac001=?)  and ('"+obj[1]+"' is null or aac002=?) and ('"+obj[2]+"' is null or aac003 like '%'||?||'%')";
    	return  sys.getGrid(sql, obj, parms, false);
    } 
    /**
	 * 查询个人基础日志信息
	 * @author bjh
	 * @param obj
	 * @param parms
	 * @throws Exception
	 */
    public HashMap getTAc01(Object[] obj,HashMap parms) throws Exception {
    	String sql="select domainid,(select name from sys_log_bm where id=log_type) as log_type,(select name from sys_log_bm where id=czqd) as czqd,(select name from sys_log_bm where id=czrlb) as czrlb,userid,rwh" +
    			",content,ip_address,browser,open_time,datain,dataout from v_sys_log where ('"+obj[0]+"' is null or log_type=? ) and ('"+obj[1]+"' is null or userid=? )" +
    			" and ('"+obj[2]+"' is null or czqd=? ) and ('"+obj[3]+"' is null or czrlb=? )";
    	return  sys.getGrid(sql, obj, parms, false);
    } 
    /**
   	 * 查询个人基础日志类型
   	 * @author bjh
   	 * @param obj
   	 * @param parms
   	 * @throws Exception
   	 */
     public List getltAc01(String log_type) throws Exception {
       	String sql="select id,name from sys_log_bm where lx=? and id not in ('T10')";
	    List data = sys.query(sql, new Object[] {log_type} , true);
	    return data;
     }
	/**
	 * 查询个人基础信息变更
	 * @author bjh
	 * @param obj
	 * @param parms
	 * @throws Exception
	 */
	public HashMap getAc01bg(Object[] obj,HashMap parms) throws Exception {
		String sql="select * from v_ac01_bg where ('"+obj[0]+"' is null or aac001=?)  and ('"+obj[1]+"' is null or aac002=?) " +
				   " and ('"+obj[2]+"' is null or aac003 like '%'||?||'%')";
	    return  sys.getGrid(sql, obj, parms, false);
	} 
	/**
	 * 根据id获取个人基础信息
	 * @author bjh
	 * @param id
	 * @throws Exception
	 */
	public HashMap getAC01Data (String id) throws Exception {
	    AC01 vo = new AC01();
	    String sql = "select * from ac01 where AAC001 = ?";
	    List data = sys.query(sql, new Object[] {id} , true);
	    return data.size() > 0 ? (HashMap)data.get(0) : null;
	} 
	/**
	 * 新增个人基础信息
	 * @author bjh 
	 * @param obj
	 * @throws Exception
	 */
	public String insertAC01(HashMap obj ) throws Exception {
		Map map = new HashMap();
	 	String aaz002 = sys.callFunction("ZJ_GET_EVENTID", map);
	 	String[] str = aaz002.split("&");
	 	AC01 vo = new AC01();
	 	String id = str[0];
	 	obj.put("aaz002", id);
	 	vo = (AC01)Util.MapToVo(vo, obj);
	 	obj.put("aac163", obj.get("aac161"));
	 	obj.put("aae135", obj.get("aac002"));
	 	obj.put("aab200", "320100");
	 	String value1 = service.people_keyInfo(obj);
	 	String value2 = service.addPeople_conInfo(obj);
	 	String value = service.callWebservice(value1, value2, "1", "11");
	 	System.out.println(value);
		if(value.contains("JS") && !value.contains("ORA-")){
			obj.put("baz805", value);
	 	}else{
	 		return value ;
	 	}
	 	String ry = sys.callDBFuncProce("zy_set_ac01.chk_ryda_xzx", "function", obj);
	 	String[] str1 = ry.split("&") ;
	 	if (str1[0].equals("0")){
	 		String ss = sys.callDBFuncProce("zy_set_ac01.insert_ac01", "function", obj);
	 		String[] str2 = ss.split("&") ;
	     	if (str2[0].equals("0")) {
	     		return "保存成功，社会保障卡号为:"+ str2[1].substring(6,17);
	     	}else{
	     		return str2[0];	
	     	}
	 	}else{
	 		return str1[0];	
	 	}
	} 
	/**
	 * 新增特殊人员基础信息
	 * @author bjh 
	 * @param obj
	 * @throws Exception
	 */
	public String inserttsadd(HashMap obj ) throws Exception {
		Map map = new HashMap();
	 	String aaz002 = sys.callFunction("ZJ_GET_EVENTID", map);
	 	String[] str = aaz002.split("&");
	 	AC01 vo = new AC01();
	 	String id = str[0];
	 	obj.put("aaz002", id);
	 	obj.put("tstz", "1");
	 	vo = (AC01)Util.MapToVo(vo, obj);
	 	obj.put("baz805", "JS0000000002");
	 	String ry = sys.callDBFuncProce("zy_set_ac01.chk_ryda_xzx", "function", obj);
	 	String[] str1 = ry.split("&") ;
	 	if (str1[0].equals("0")){
	 		String ss = sys.callDBFuncProce("zy_set_ac01.insert_ac01", "function", obj);
	 		String[] str2 = ss.split("&") ;
	     	if (str2[0].equals("0")) {
	     		return "保存成功，社会保障卡号为:"+ str2[1].substring(6,17);
	     	}else{
	     		return str2[0];	
	     	}
	 	}else{
	 		return str1[0];	
	 	}
	} 
	/**
	 * 更新个人基础信息
	 * @author bjh
	 * @param obj
	 * @throws Exception
	 */
	public String modifiedAC01(HashMap obj) throws Exception {
		AC01 vo = new AC01();
		vo = (AC01)Util.MapToVo(vo, obj);
	 	String jc = sys.callDBFuncProce("zy_set_ac01.chk_rydaxg_data", "function", obj);
	 	String[] str1 = jc.split("&") ;
	    if (str1[0].equals("0")){
	    	String ss = sys.callDBFuncProce("zy_set_ac01.update_ac01", "function", obj);
	     	String[] str2 = ss.split("&") ;
	        if (str2[0].equals("0")) {
	        	return "修改成功";
	        }else{
	        	return str2[0];	
	        }
	    }else{
	    	return str1[0];	
	    }
	} 
	/**
	 * 根据id获取修改前的个人基础信息
	 * @param id
	 * @return
	 * @throws Exception
	 */
	public HashMap getAc01Datas(String id) throws Exception {
		String sql="select aac003,aac058,aac002,to_char(aacc01,'yyyy-mm-dd') as aacc01,to_char(aac006,'yyyy-mm-dd') as aac006,aac004,aac005,aac161,aae005 from ac01 where  aac001=?";
		List data = sys.query(sql, new Object[] {id}, true);
		return data.size() > 0 ? (HashMap)data.get(0) : null;
	} 
	/**
	 * 根据aac058和aac147查询个人基础信息
	 * @author bjh 
	 * @param aac058
	 * @param aac147
	 * @throws Exception
	 */
	public HashMap getAAC147 (String aac058,String aac002) throws Exception {
		String sql = "select * from ac01 where aac058 = ? and aac002 = ?";
	    List data = sys.query(sql, new Object[] {aac058, aac002}, true);
	    return data.size() > 0 ? (HashMap)data.get(0) : null;
	} 
	/**
	 * 获取下拉数据
	 * @author bjh 
	 * @param lx
	 * @throws Exception
	 */
	public List getSelect(String lx) throws Exception {
		 String sql = "select aaa103,aaa102 FROM aa10 where aaa100=? order by aaz093";
	     List data = sys.query(sql, new Object[] {lx}, true);
	     return data;
	} 
	/**
	 * 获取证件类型下拉列表
	 * @param lx
	 * @return
	 * @throws Exception
	 */
	public List getSelectaac058(String lx) throws Exception {
	  	String sql = "select aaa103,aaa102 FROM aa10 where aaa100=? and AAA102 in ('01','04','06','07','08')";
	  	List data = sys.query(sql, new Object[] {lx}, true);
	  	return data;
	}
	 /**
	  * 校验身份证
	  * @param obj
	  * @return
	  * @throws Exception
	  */
	public String checksfz(HashMap obj) throws Exception {
		String ss = sys.callDBFuncProce("zj_gf.chk_shbzh", "function", obj).toString();		
		String[] result = ss.split("&") ;
		if(result[0].equals("0")) {
			return "0";
		}else {		
			String[] str =result[0].split(":");
			return str[0];
		} 
	}
	/**
	 * 批量登记个人信息
	 * @param request
	 * @param response
	 * @throws Exception
	*/
	public String insertUnitpl(HashMap obj) throws Exception{
		String eventId = (String) obj.get("eventid");
		System.out.println("eventId:"+eventId);
		if(eventId.contains(">")){
			String[]  str = eventId.split(">");
			String str1 = str[1].substring(0,str[1].lastIndexOf("<"));
			obj.put("eventid", str1);
		}
		String ry = sys.callDBFuncProce("zy_set_ac01.chk_ac01_pl", "function", obj); 
		/*String sql="select * from ZJ_TMP t where eventid='"+obj.get("eventid").toString()+"' and execcode='0'";
		  List list=sys.query(sql, new Object[] {},true);
		  String eventid="";
		  String c3="",c5="";
		  for(int i=0;i<list.size();i++){
		  HashMap map=(HashMap) list.get(i);
		  eventid=map.get("eventid").toString();
		  c3=map.get("c3").toString();
		  c5=map.get("c5").toString();
		  String SRYSBM="";
		  sys.executeSql("update ZJ_TMP set c10='"+SRYSBM+"' where eventid='"+eventid+"' and c3='"+c3+"' ");
		}*/
		System.out.println(ry);
		String[] str1 = ry.split("&") ;
		if(null!=str1){
			if("0".equals(str1[0])){
				String ss = sys.callDBFuncProce("zy_set_ac01.insert_ac01_pl", "function", obj).toString();
				String[] str = ss.split("&");
				if(null!=str)return str[0];
				else return "err";
			}else{
				return str1[0];
			}
		}
		return "err";
	} 
	/**
	 * 批量导入个人信息校验
	 * @author fcl
	 * @param request
	 * @param response
	 * @throws Exception
	 */
    public String insertUnitpl1(HashMap obj) throws Exception{
		
		String eventId = (String) obj.get("eventid");
		System.out.println("eventId:"+eventId);
		if(eventId.contains(">")){
			String[]  str = eventId.split(">");
			String str1 = str[1].substring(0,str[1].lastIndexOf("<"));
			obj.put("eventid", str1);
		}
		String ry = sys.callDBFuncProce("zy_set_ac01.chk_ac01_pl", "function", obj); 
		System.out.println(ry);
		String[] str1 = ry.split("&") ;
		return str1[0]+","+eventId+","+str1[1];
	} 
	/**
	 * 错误信息 
	 * @author duy
	 * @param obj
	 * @param parms
	 * @throws Exception
	 */
	public HashMap gettemp(Object[] obj, HashMap parms) throws Exception {
		String sql = "select * from v_ac01_tmp where eventid =?  ";			
		HashMap map = sys.getGrid(sql, obj, parms, false);
		return map;
	}
}

